package core

import (
	"github.com/casbin/casbin/v2"
	"github.com/casbin/casbin/v2/model"
	gormadapter "github.com/casbin/gorm-adapter/v3"
	"github.com/sirupsen/logrus"
	"study/server/global"
)

func InitCasbin() *casbin.CachedEnforcer {
	a, _ := gormadapter.NewAdapterByDB(global.DB)
	m, err := model.NewModelFromFile("server/core/model.pml")
	if err != nil {
		logrus.Fatal("字符串加载模型失败!", err)
		return nil
	}
	e, _ := casbin.NewCachedEnforcer(m, a)
	e.SetExpireTime(60 * 60)
	_ = e.LoadPolicy()
	return e
}
